/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import bean.EmailVo;
import iservice.IEmailNotifyService;
import java.util.Date;
import javax.mail.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 *
 * @author root
 */
@Service
public class EmailNotifyService implements IEmailNotifyService{

    @Autowired
    private JavaMailSender emailTemplate;
    @Autowired
    private SimpleMailMessage simpleMailMessage;

//    public void setEmailTemplate(JavaMailSender emailTemplate) {
//        this.emailTemplate = emailTemplate;
//    }
    
    
    
    @Override
    public void sendEmailMessageOfSimpleText(EmailVo emailVo, Date date) {
        simpleMailMessage.setTo(emailVo.getReceivers());
        if(emailVo.getBcc()!=null&&emailVo.getBcc().length > 0)
        {
            simpleMailMessage.setBcc(emailVo.getBcc());
        }
        if(emailVo.getCc()!=null&&emailVo.getCc().length > 0)
        {
            simpleMailMessage.setCc(emailVo.getCc());
        }
        simpleMailMessage.setText(emailVo.getEmailContent());

        if(null == date)
        {
            date = new Date();
        }
        simpleMailMessage.setSentDate(date);
        simpleMailMessage.setSubject(emailVo.getSubject());

        emailTemplate.send(simpleMailMessage);
    }

    @Override
    public void sendEmailMessageOfHtmlText(EmailVo emailVo, Date date) throws MessagingException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void sendEmailMessageOfAttachedFileAndSimpleText(EmailVo emailVo, Date date, boolean isHtmlText) throws MessagingException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
